package com.falcon.mojo;

import com.falcon.util.PathUtil;
import com.falcon.util.PomUtil;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.dom4j.Document;
import org.dom4j.Element;

/** 备份原pom、合并生成新的pom */
@Mojo(name = "dependency-clean")
public class DependencyCleanMojo extends AbsMojo {

    public void execute() throws MojoExecutionException, MojoFailureException {

        // 获取汇总 pom.xml 的 dom 对象
        String currentPomFile = PathUtil.getPomPath(this.project);

        Document currentDocument = PomUtil.getDocument(currentPomFile);

        Element dependencies = currentDocument.getRootElement().element("dependencies");

        dependencies.clearContent();

        // 如果是覆盖源码中的 pom，则直接写入原 pom.xml 中
        getLog().info("准备覆盖原来的pom..");
        PomUtil.write(currentDocument, currentPomFile);
    }


}
